package com.copm.ifm.servers.sys.controller;


import com.copm.ifm.base.api.pojo.PageDTO;
import com.copm.ifm.base.basic.ServiceResponse;
import com.copm.ifm.base.service.base.BaseController;
import com.copm.ifm.servers.sys.entity.SysBusinessType;
import com.copm.ifm.servers.sys.entity.SysTenant;
import com.copm.ifm.servers.sys.service.SysBusinessTypeService;
import com.copm.ifm.servers.sys.service.SysTenantService;
import com.copm.ifm.servers.sys.vo.SysBusinessTypeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 业务类型类
 * </p>
 *
 * @author tp
 * @since 2021-1-20
 */
@Slf4j
@Api(tags = "业务类型分类/sys-business")
@RestController
@RequestMapping("/sys-business")
public class SysBusinessTypeController extends BaseController {

    @Autowired
    SysBusinessTypeService sysBusinessTypeService;

    @Autowired
    SysTenantService sysTenantService;

    @ApiImplicitParams({
            @ApiImplicitParam(value = "分页参数条件",name = "param"),
            @ApiImplicitParam(value = "租户id",name = "tenantId"),
            @ApiImplicitParam(value = "是否需要显示(1代表不需要显示，0代表需要显示)",name = "isDisplay")
    })
    @ApiOperation("分页")
    @PostMapping("/page")
    public ServiceResponse<List<SysBusinessTypeVO>> page(@RequestBody PageDTO<SysBusinessType> param,
                                                         @RequestParam Integer tenantId,
                                                         @RequestParam Integer isDisplay) {
        return success(sysBusinessTypeService.selectForPage(param, tenantId, isDisplay));
    }

    @ApiOperation("修改-业务类型update")
    @PutMapping
    public ServiceResponse<SysBusinessType> update(@RequestBody SysBusinessType entity) {
        sysTenantService.updateBusinessById(entity);
        return success(entity);
    }

    @ApiOperation("拥有所有业务类型权限")
    @GetMapping("/all/auth")
    public ServiceResponse<?> update(@RequestParam Integer tenantId){
        sysTenantService.updateAllBusinessById(tenantId);
        return success();
    }

    @ApiOperation("修改所有业务类型")
    @PostMapping("/save/all")
    public ServiceResponse<?> saveAll(@RequestParam List<SysBusinessType> sysBusinessTypeList){
        sysBusinessTypeService.saveBatch(sysBusinessTypeList);
        return success();
    }
}
